package com.wang.example.netty.codec.error;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;

public class EchoClientInHandler extends ChannelInboundHandlerAdapter {
    /**
     * 客户端读取到数据
     * @param ctx
     * @param msg
     * @throws Exception
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg)
            throws Exception {
        ByteBuf bufMsg = (ByteBuf) msg;
        System.out.println("client receive:"+bufMsg.toString(CharsetUtil.UTF_8));
        //释放与池化的 ByteBuf 实例相关的内存
        ReferenceCountUtil.release(msg);
    }
}
